efi: Provide a shim for load_image, start_image, unload_image
authorJulian Andres Klode <julian.klode@canonical.com>
Mon, 24 Jul 2023 13:26:10 +0000 (15:26 +0200)
committerFelix Zielcke <fzielcke@z-51.de>
Thu, 3 Jul 2025 16:35:51 +0000 (18:35 +0200)
commit3d40ef35f2b49aa70a5f58e1b71ba6600b39fce8
treeb510ef6a02466afa8119e6a1c62aaa3bffebf421
parent9b5147ee25428ed15774e8b4adc8c0e1f1e7ce0e
efi: Provide a shim for load_image, start_image, unload_image

Provide custom implementations of load_image(), start_image(),
and unload_image() to workaround shim just forwarding those
calls to the firmware.

The code consumes a PE-COFF image loaded into memory. The functions

* check validity of header
* copy the sections
* relocate the code
* invalidate the instruction cache
* execute the image
* return to caller

This was previously in use in Ubuntu on riscv64 and arm64 only,
exposed as a single function  grub_efi_run_image(). It was
originally written by Heinrich and split up into 3 functions
by Julian to integrate with the upstream boot loader.

Caveats:

- We do not always check for over and underflows, but at the
  point we reach this loader, the file has been verified by
  shim already, so this is not much of a concern.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Signed-off-by: Julian Andres Klode <julian.klode@canonical.com>
Gbp-Pq: Topic secure-boot
Gbp-Pq: Name efi-use-peimage-shim.patch
grub-core/Makefile.core.def
grub-core/loader/efi/peimage.c [new file with mode: 0644]
include/grub/efi/peimage.h [new file with mode: 0644]